#import <Foundation/Foundation.h>

int PrintPathInfo() {
	NSLog(@"\n\nSection 1");
	NSString *path = @"~";
	NSString *targetPath = [path stringByExpandingTildeInPath];
	NSLog(@"My Home Folder is at '%@'", targetPath);
	NSArray *pathArray = [targetPath pathComponents];
	
	NSString *string = [[NSString alloc] init];
	NSString *result = [[NSString alloc] init];
	
	for (int i = 0; i < [pathArray count]; i++) {
		string = [pathArray objectAtIndex:i];
		result = [result stringByAppendingFormat:@"%@\n", string];
	}
	NSLog(@"%@", result);
	
	[string release];
	[result release];
//	[pathArray release];
	return 0;
}

int PrintProcessInfo() {
	NSLog(@"\n\nSection 2");
	NSProcessInfo *pi = [NSProcessInfo processInfo];
	NSString *piName = [pi processName];
	int piID = [pi processIdentifier];
	NSLog(@"Process Name: '%@' Process ID: '%d'", piName, piID);

//	[pi release];
	[piName release];
	return 0;
}

int PrintBookmarkInfo() {
	NSLog(@"\n\nSection 3");
	NSURL *key1 = [NSURL URLWithString:@"http://www.stanford.edu"];
	NSURL *key2 = [NSURL URLWithString:@"http://www.apple.com"];
	NSURL *key3 = [NSURL URLWithString:@"http://cs193p.stanford.edu"];
	NSURL *key4 = [NSURL URLWithString:@"http://itunes.stanford.edu"];
    NSURL *key5 = [NSURL URLWithString:@"http://stanfordshop.com"];
	
	NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
	[dict setObject:key1 forKey:@"Stanford University"];
	[dict setObject:key2 forKey:@"Apple"];
	[dict setObject:key3 forKey:@"CS193P"];
	[dict setObject:key4 forKey:@"Stanford on iTunes U"];
	[dict setObject:key5 forKey:@"Stanford Mall"];

	for(NSString *key in dict) {
		if ([key hasPrefix:@"Stanford"]) {
			NSLog(@"Key: '%@', URL: '%@'", key, [dict objectForKey:key]);
		}
	}
	
	[dict release];
	return 0;
}
int	PrintIntrospectionInfo() {
	NSMutableString *ms = [[NSMutableString alloc] init];
	BOOL member = [ms isMemberOfClass:[NSString class]];
	BOOL kind = [ms isKindOfClass:[NSString class]];
	BOOL res = [ms respondsToSelector:@selector(lowercaseString)];
	NSLog(@"Class Name:   %@", [ms className]);
	NSLog(@"is member of NSString:   %d", member);
	NSLog(@"is kind of NSString:   %d", kind);
	NSLog(@"respondes to selector:   %d", res);
	if (res) {
		NSLog(@"lowercaseString is:  hello world!");
	}
	
	[ms release];
	return 0;
}

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	PrintPathInfo();
	PrintProcessInfo();
	PrintBookmarkInfo();
	PrintIntrospectionInfo();

    [pool drain];
    return 0;
}